<?php
defined('BASEPATH') or exit('No direct script access allowed');
?>
<style>
    .table-bordered, .table-bordered > thead > tr > th, .table-bordered > tbody > tr > th, .table-bordered > tfoot > tr > th, .table-bordered > thead > tr > td, .table-bordered > tbody > tr > td, .table-bordered > tfoot > tr > td {
        border: 1px solid #dcdcdc;
    }

    .productrow {
        clear: both;
        display: block;
    }

    .proimg {
        float: left;
        text-align: center;
        margin-right: 4px;
    }

    .proimg img {
        width: 90px;
        border: 1px solid #ddd;
        display: block;
    }

    /*定义类名为.thead-blue的样式*/
    .table .thead-blue th {
        color: #fff;
        background-color: #3c8dbc;
    }
</style>
<div class="row">
    <div class="col-sm-12">
        <div class="box">
            <div class="box-header with-border">
                <h2 class="page-header">
                    <i class="fa fa-trash-o"></i> 垃圾箱
                </h2>
            </div>
            <div class="box-body">
                <div class="mb-10">
                    <?php echo form_open(current_url(), array('class' => 'form-inline', 'method' => 'get', 'id' => 'search_goods')); ?>
                    <div class="form-group" style="margin-right:15px;">
                        <select class="form-control" name="sitetype">
                            <option value="0">所有类型</option>
                            <?php foreach ($sitetype as $k => $s): ?>
                                <option value="<?php echo $k; ?>"><?php echo $s; ?></option>
                            <?php endforeach; ?>
                        </select>
                    </div>
                    <div class="form-group" style="margin-right:15px;">
                        <select class="form-control" name="state">
                            <option value="0">所有站点</option>
                            <?php foreach ($sindex as $k => $s): ?>
                                <option value="<?php echo $k; ?>" <?php if ($k == $state) echo " selected"; ?>><?php echo $s; ?></option>
                            <?php endforeach; ?>
                        </select>
                    </div>
                    <div class="form-group" style="margin-right:15px;">
                        <?php echo form_input($keyword); ?>
                    </div>
                    <div class="form-group" style="margin-right:15px;">
                        <?php echo tpl_form_field_daterange("timelimit", ["start" => date("Y-m-d", strtotime("-800 days")), "end" => date("Y-m-d")], false); ?>
                    </div>
                    <?php echo form_button(array('type' => 'submit', 'class' => 'btn btn-sm btn-primary btn-flat', 'content' => "搜索询盘")); ?>
                    <span class="btn btn-flat btn-info btn-sm" id="export">导出订单</span>
                    <?php echo form_close(); ?>
                </div>

                <table class="table table-bordered table-hover table-dark" style="margin-top:20px;">
                    <?php if ($loglist): ?>
                        <table class="table table-bordered table-hover table-dark" style="margin-top:20px;">
                            <thead class="thead-blue">
                            <tr>
                                <th>站点</th>
                                <th>真实姓名</th>
                                <th>邮箱</th>
                                <th>电话</th>
                                <th>数量</th>
                                <th width="350">留言</th>
                                <th>时间</th>
                                <th style="text-align: center" width="100">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <?php foreach ($loglist as $item): ?>
                                <tr shopid="<?php echo $item["id"]; ?>">
                                    <td>
                                        <a href="/backend/sites/order/index/<?php echo $item["siteid"]; ?>"
                                           target="_blank"><?php echo $sindex[$item["siteid"]]; ?></a>
                                    </td>
                                    <td>
                                        <?php
                                        if (ismobile($item["agent"])) {
                                            echo '<i class="fa fa-phone-square" aria-hidden="true"></i>';
                                        } else {

                                        }
                                        ?><?php echo $item["realname"]; ?>
                                    </td>
                                    <td>
                                        <?php echo $item["email"]; ?>
                                    </td>
                                    <td>
                                        <?php echo $item["phone"]; ?>
                                    </td>
                                    <td>
                                        <?php
                                        if ($item["quantity"]) {
                                            echo $item["quantity"];
                                        } else {
                                            echo '无';
                                        } ?>
                                    </td>
                                    <td width="">
                                        <?php echo $item["info"]; ?>
                                    </td>
                                    <td><?php echo date("Y-m-d H:i", strtotime($item["addtime"])); ?></td>
                                    <td style="text-align: center">
                                        <span class="btn btn-xs btn-flat btn-info btn-repeat" itemid="<?php echo $item["id"] ;?>">
                                        <i class="fa fa-repeat fa-lg"></i>
                                    </span>
                                    </td>
                                </tr>
                            <?php endforeach; ?>
                            </tbody>
                        </table>
                    <?php endif; ?>
<script>
    $("span.btn-repeat").on("click", function (event) {
        var cid = $(this).attr("itemid");
        var row = $(this).parent().parent();
        layer.confirm("确认要恢复吗，恢复后将重新出现在询盘列表？", {title: "确认"}, function (index) {
            $.ajax({
                type: "post",
                url: "/backend/OrdersTrash/ordersajaxrep",
                dataType: "json",
                data: {"cid": cid},
                error: function () {},
                success: function (result) {
                    if (result["status"] == 1) {
                        row.remove();
                    } else {
                        layer.msg(result["msg"]);
                    }
                },
            });
            layer.close(index);
        });
    });

    $("span#export").on("click", function () {
        layer.confirm("最好不要导出垃圾箱的订单", {title: "确认导出"}, function (index) {
            layer.close(index);
            var url = window.location.href;
            var newUrl = changeURLArg(url, "export", "1");
            window.location.href = newUrl;
        });
    });

    function changeURLArg(url, arg, arg_val) {
        var pattern = arg + '=([^&]*)';
        var replaceText = arg + '=' + arg_val;
        if (url.match(pattern)) {
            var tmp = '/(' + arg + '=)([^&]*)/gi';
            tmp = url.replace(eval(tmp), replaceText);
            return tmp;
        } else {
            if (url.match('[\?]')) {
                return url + '&' + replaceText;
            } else {
                return url + '?' + replaceText;
            }
        }
        return url + '\n' + arg + '\n' + arg_val;
    }
</script>